package structure.Composite;

import java.util.LinkedList;

/**
 * Created by LYJ on 2016/10/19.
 * 树枝
 */
public class Composite extends Component{

    private LinkedList<Component> children;

    public Composite(String name) {
        super(name);
        this.children=new LinkedList<>();
    }
    @Override
    protected void add(Component component) {
        children.add(component);
    }

    @Override
    protected void remove(Component component) {
        children.remove(component);
    }

    @Override
    protected void operation(int depth) {
        String temp="";
        for(int i=0;i<depth;i++){
            temp+="    ";
        }
        LinkedList<Component> components=getChildren();
        System.out.println(temp+name);
        for(Component c:components){
            c.operation(depth+1);
        }
    }

    @Override
    protected LinkedList<Component> getChildren() {
        return children;
    }


}
